package me.boot.db.mybatis.condition;

import cn.hutool.core.util.StrUtil;
import me.boot.db.mybatis.propertites.DbProperties;
import me.boot.db.mybatis.propertites.TenantMode;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;


public abstract class BaseTenantModeCondition implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String value = context.getEnvironment().getProperty(DbProperties.PREFIX + ".tenant.mode");
        return StrUtil.equalsAnyIgnoreCase(value, getMode().name());
    }


    abstract protected TenantMode getMode();

}
